extends Faci

var items = ItemPck.new()
var chas = ItemPck.new()

func _data():
	isCs = true
	isPressed = true
	name = "铁匠"
	dec = "铁匠加入你的队伍，他能帮你合成和升级装备"
	weight = 0.5
	tab = "world"
	num = 1

var n1 = 3
var g = 100

func _in():
	lv = 0
	yield(ctime(0.1),"timeout")
	matMoveUp(sys.mapScene.getNullCell(sys.mapScene.playFaci.cell + Vector2(1,1)))
	self.visible = true

func _trig():
	sys.eventDlg.txt(dec)
	var cha = data.newBase("c_1_tj")
	sys.player.addAlterCha(cha)
	del()
	sys.eventDlg.txt("在部队页面中，把3个同等级装备放入铁匠身上即可完成合成")
	return
		
func _r(items):
	if items == null :return
	if items.items[0].lv != items.items[1].lv || items.items[1].lv != items.items[2].lv :
		sys.eventDlg.txt(tr("装备等级不一致"))
		return
	var ii = items.items[0]
	for i in items.items:
		sys.player.items.delItem(i)
	items.clear()
	eqpSelDlg(ii.lv + 1)
	n1 -= 1	
	if n1 <= 0 :self.invalid = true
	
func _r2(aitem):
	if aitem == null :return
	var g3 = 100 * pow(3,aitem.lv-1) * 0.2
	var inx2 = yield(sys.eventDlg.selBB([tr("支付 %d 金币") % g3,tr("放弃")]),"onSel")
	if inx2 == 0 :
		if sys.player.subItem("m_gold",g3) == false: 
			sys.eventDlg.txt(tr("金币 不足"))
			return
	else:
		return
	var item = data.newBase(aitem.id)
	item.create(aitem.lv)
	sys.player.items.delItem(aitem)
	var itemPck = ItemPck.new()
	itemPck.addItem(item)
	sys.eventDlg.items(itemPck)

func getSave():
	var ds = {
		n1 = n1,
	}
	ds.merge(.getSave())
	return ds
	
func setSave(ds):
	.setSave(ds)
	dsSet("n1",ds)
